1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.MediaStream;
26 
27 private import gdk.PaintableIF;
28 private import gdk.PaintableT;
29 private import gdk.Surface;
30 private import glib.ErrorG;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 
36 
37 /**
38  * `GtkMediaStream` is the integration point for media playback inside GTK.
39  * 
40  * GTK provides an implementation of the `GtkMediaStream` interface that
41  * is called [class@Gtk.MediaFile].
42  * 
43  * Apart from application-facing API for stream playback, `GtkMediaStream`
44  * has a number of APIs that are only useful for implementations and should
45  * not be used in applications:
46  * [method@Gtk.MediaStream.prepared],
47  * [method@Gtk.MediaStream.unprepared],
48  * [method@Gtk.MediaStream.update],
49  * [method@Gtk.MediaStream.ended],
50  * [method@Gtk.MediaStream.seek_success],
51  * [method@Gtk.MediaStream.seek_failed],
52  * [method@Gtk.MediaStream.gerror],
53  * [method@Gtk.MediaStream.error],
54  * [method@Gtk.MediaStream.error_valist].
55  */
56 public class MediaStream : ObjectG, PaintableIF
57 {
58 	/** the main Gtk struct */
59 	protected GtkMediaStream* gtkMediaStream;
60 
61 	/** Get the main Gtk struct */
62 	public GtkMediaStream* getMediaStreamStruct(bool transferOwnership = false)
63 	{
64 		if (transferOwnership)
65 			ownedRef = false;
66 		return gtkMediaStream;
67 	}
68 
69 	/** the main Gtk struct as a void* */
70 	protected override void* getStruct()
71 	{
72 		return cast(void*)gtkMediaStream;
73 	}
74 
75 	/**
76 	 * Sets our main struct and passes it to the parent class.
77 	 */
78 	public this (GtkMediaStream* gtkMediaStream, bool ownedRef = false)
79 	{
80 		this.gtkMediaStream = gtkMediaStream;
81 		super(cast(GObject*)gtkMediaStream, ownedRef);
82 	}
83 
84 	// add the Paintable capabilities
85 	mixin PaintableT!(GtkMediaStream);
86 
87 
88 	/** */
89 	public static GType getType()
90 	{
91 		return gtk_media_stream_get_type();
92 	}
93 
94 	/**
95 	 * Pauses the media stream and marks it as ended.
96 	 *
97 	 * This is a hint only, calls to [method@Gtk.MediaStream.play]
98 	 * may still happen.
99 	 *
100 	 * The media stream must be prepared when this function is called.
101 	 *
102 	 * Deprecated: Use [method@Gtk.MediaStream.stream_ended] instead
103 	 */
104 	public void ended()
105 	{
106 		gtk_media_stream_ended(gtkMediaStream);
107 	}
108 
109 	/**
110 	 * Sets @self into an error state using a printf()-style format string.
111 	 *
112 	 * This is a utility function that calls [method@Gtk.MediaStream.gerror].
113 	 * See that function for details.
114 	 *
115 	 * Params:
116 	 *     domain = error domain
117 	 *     code = error code
118 	 *     format = printf()-style format for error message
119 	 *     args = `va_list` of parameters for the message format
120 	 */
121 	public void errorValist(GQuark domain, int code, string format, void* args)
122 	{
123 		gtk_media_stream_error_valist(gtkMediaStream, domain, code, Str.toStringz(format), args);
124 	}
125 
126 	/**
127 	 * Sets @self into an error state.
128 	 *
129 	 * This will pause the stream (you can check for an error
130 	 * via [method@Gtk.MediaStream.get_error] in your
131 	 * GtkMediaStream.pause() implementation), abort pending
132 	 * seeks and mark the stream as prepared.
133 	 *
134 	 * if the stream is already in an error state, this call
135 	 * will be ignored and the existing error will be retained.
136 	 *
137 	 * To unset an error, the stream must be reset via a call to
138 	 * [method@Gtk.MediaStream.unprepared].
139 	 *
140 	 * Params:
141 	 *     error = the `GError` to set
142 	 */
143 	public void gerror(ErrorG error)
144 	{
145 		gtk_media_stream_gerror(gtkMediaStream, (error is null) ? null : error.getErrorGStruct(true));
146 	}
147 
148 	/**
149 	 * Gets the duration of the stream.
150 	 *
151 	 * If the duration is not known, 0 will be returned.
152 	 *
153 	 * Returns: the duration of the stream or 0 if not known.
154 	 */
155 	public long getDuration()
156 	{
157 		return gtk_media_stream_get_duration(gtkMediaStream);
158 	}
159 
160 	/**
161 	 * Returns whether the streams playback is finished.
162 	 *
163 	 * Returns: %TRUE if playback is finished
164 	 */
165 	public bool getEnded()
166 	{
167 		return gtk_media_stream_get_ended(gtkMediaStream) != 0;
168 	}
169 
170 	/**
171 	 * If the stream is in an error state, returns the `GError`
172 	 * explaining that state.
173 	 *
174 	 * Any type of error can be reported here depending on the
175 	 * implementation of the media stream.
176 	 *
177 	 * A media stream in an error cannot be operated on, calls
178 	 * like [method@Gtk.MediaStream.play] or
179 	 * [method@Gtk.MediaStream.seek] will not have any effect.
180 	 *
181 	 * `GtkMediaStream` itself does not provide a way to unset
182 	 * an error, but implementations may provide options. For example,
183 	 * a [class@Gtk.MediaFile] will unset errors when a new source is
184 	 * set, e.g. with [method@Gtk.MediaFile.set_file].
185 	 *
186 	 * Returns: %NULL if not in an
187 	 *     error state or the `GError` of the stream
188 	 */
189 	public ErrorG getError()
190 	{
191 		auto __p = gtk_media_stream_get_error(gtkMediaStream);
192 
193 		if(__p is null)
194 		{
195 			return null;
196 		}
197 
198 		return new ErrorG(cast(GError*) __p);
199 	}
200 
201 	/**
202 	 * Returns whether the stream is set to loop.
203 	 *
204 	 * See [method@Gtk.MediaStream.set_loop] for details.
205 	 *
206 	 * Returns: %TRUE if the stream should loop
207 	 */
208 	public bool getLoop()
209 	{
210 		return gtk_media_stream_get_loop(gtkMediaStream) != 0;
211 	}
212 
213 	/**
214 	 * Returns whether the audio for the stream is muted.
215 	 *
216 	 * See [method@Gtk.MediaStream.set_muted] for details.
217 	 *
218 	 * Returns: %TRUE if the stream is muted
219 	 */
220 	public bool getMuted()
221 	{
222 		return gtk_media_stream_get_muted(gtkMediaStream) != 0;
223 	}
224 
225 	/**
226 	 * Return whether the stream is currently playing.
227 	 *
228 	 * Returns: %TRUE if the stream is playing
229 	 */
230 	public bool getPlaying()
231 	{
232 		return gtk_media_stream_get_playing(gtkMediaStream) != 0;
233 	}
234 
235 	/**
236 	 * Returns the current presentation timestamp in microseconds.
237 	 *
238 	 * Returns: the timestamp in microseconds
239 	 */
240 	public long getTimestamp()
241 	{
242 		return gtk_media_stream_get_timestamp(gtkMediaStream);
243 	}
244 
245 	/**
246 	 * Returns the volume of the audio for the stream.
247 	 *
248 	 * See [method@Gtk.MediaStream.set_volume] for details.
249 	 *
250 	 * Returns: volume of the stream from 0.0 to 1.0
251 	 */
252 	public double getVolume()
253 	{
254 		return gtk_media_stream_get_volume(gtkMediaStream);
255 	}
256 
257 	/**
258 	 * Returns whether the stream has audio.
259 	 *
260 	 * Returns: %TRUE if the stream has audio
261 	 */
262 	public bool hasAudio()
263 	{
264 		return gtk_media_stream_has_audio(gtkMediaStream) != 0;
265 	}
266 
267 	/**
268 	 * Returns whether the stream has video.
269 	 *
270 	 * Returns: %TRUE if the stream has video
271 	 */
272 	public bool hasVideo()
273 	{
274 		return gtk_media_stream_has_video(gtkMediaStream) != 0;
275 	}
276 
277 	/**
278 	 * Returns whether the stream has finished initializing.
279 	 *
280 	 * At this point the existence of audio and video is known.
281 	 *
282 	 * Returns: %TRUE if the stream is prepared
283 	 */
284 	public bool isPrepared()
285 	{
286 		return gtk_media_stream_is_prepared(gtkMediaStream) != 0;
287 	}
288 
289 	/**
290 	 * Checks if a stream may be seekable.
291 	 *
292 	 * This is meant to be a hint. Streams may not allow seeking even if
293 	 * this function returns %TRUE. However, if this function returns
294 	 * %FALSE, streams are guaranteed to not be seekable and user interfaces
295 	 * may hide controls that allow seeking.
296 	 *
297 	 * It is allowed to call [method@Gtk.MediaStream.seek] on a non-seekable
298 	 * stream, though it will not do anything.
299 	 *
300 	 * Returns: %TRUE if the stream may support seeking
301 	 */
302 	public bool isSeekable()
303 	{
304 		return gtk_media_stream_is_seekable(gtkMediaStream) != 0;
305 	}
306 
307 	/**
308 	 * Checks if there is currently a seek operation going on.
309 	 *
310 	 * Returns: %TRUE if a seek operation is ongoing.
311 	 */
312 	public bool isSeeking()
313 	{
314 		return gtk_media_stream_is_seeking(gtkMediaStream) != 0;
315 	}
316 
317 	/**
318 	 * Pauses playback of the stream.
319 	 *
320 	 * If the stream is not playing, do nothing.
321 	 */
322 	public void pause()
323 	{
324 		gtk_media_stream_pause(gtkMediaStream);
325 	}
326 
327 	/**
328 	 * Starts playing the stream.
329 	 *
330 	 * If the stream is in error or already playing, do nothing.
331 	 */
332 	public void play()
333 	{
334 		gtk_media_stream_play(gtkMediaStream);
335 	}
336 
337 	/**
338 	 * Same as gtk_media_stream_stream_prepared().
339 	 *
340 	 * Deprecated: Use [method@Gtk.MediaStream.stream_prepared] instead.
341 	 *
342 	 * Params:
343 	 *     hasAudio = %TRUE if the stream should advertise audio support
344 	 *     hasVideo = %TRUE if the stream should advertise video support
345 	 *     seekable = %TRUE if the stream should advertise seekability
346 	 *     duration = The duration of the stream or 0 if unknown
347 	 */
348 	public void prepared(bool hasAudio, bool hasVideo, bool seekable, long duration)
349 	{
350 		gtk_media_stream_prepared(gtkMediaStream, hasAudio, hasVideo, seekable, duration);
351 	}
352 
353 	/**
354 	 * Called by users to attach the media stream to a `GdkSurface` they manage.
355 	 *
356 	 * The stream can then access the resources of @surface for its
357 	 * rendering purposes. In particular, media streams might want to
358 	 * create a `GdkGLContext` or sync to the `GdkFrameClock`.
359 	 *
360 	 * Whoever calls this function is responsible for calling
361 	 * [method@Gtk.MediaStream.unrealize] before either the stream
362 	 * or @surface get destroyed.
363 	 *
364 	 * Multiple calls to this function may happen from different
365 	 * users of the video, even with the same @surface. Each of these
366 	 * calls must be followed by its own call to
367 	 * [method@Gtk.MediaStream.unrealize].
368 	 *
369 	 * It is not required to call this function to make a media stream work.
370 	 *
371 	 * Params:
372 	 *     surface = a `GdkSurface`
373 	 */
374 	public void realize(Surface surface)
375 	{
376 		gtk_media_stream_realize(gtkMediaStream, (surface is null) ? null : surface.getSurfaceStruct());
377 	}
378 
379 	/**
380 	 * Start a seek operation on @self to @timestamp.
381 	 *
382 	 * If @timestamp is out of range, it will be clamped.
383 	 *
384 	 * Seek operations may not finish instantly. While a
385 	 * seek operation is in process, the [property@Gtk.MediaStream:seeking]
386 	 * property will be set.
387 	 *
388 	 * When calling gtk_media_stream_seek() during an
389 	 * ongoing seek operation, the new seek will override
390 	 * any pending seek.
391 	 *
392 	 * Params:
393 	 *     timestamp = timestamp to seek to.
394 	 */
395 	public void seek(long timestamp)
396 	{
397 		gtk_media_stream_seek(gtkMediaStream, timestamp);
398 	}
399 
400 	/**
401 	 * Ends a seek operation started via GtkMediaStream.seek() as a failure.
402 	 *
403 	 * This will not cause an error on the stream and will assume that
404 	 * playback continues as if no seek had happened.
405 	 *
406 	 * See [method@Gtk.MediaStream.seek_success] for the other way of
407 	 * ending a seek.
408 	 */
409 	public void seekFailed()
410 	{
411 		gtk_media_stream_seek_failed(gtkMediaStream);
412 	}
413 
414 	/**
415 	 * Ends a seek operation started via GtkMediaStream.seek() successfully.
416 	 *
417 	 * This function will unset the GtkMediaStream:ended property
418 	 * if it was set.
419 	 *
420 	 * See [method@Gtk.MediaStream.seek_failed] for the other way of
421 	 * ending a seek.
422 	 */
423 	public void seekSuccess()
424 	{
425 		gtk_media_stream_seek_success(gtkMediaStream);
426 	}
427 
428 	/**
429 	 * Sets whether the stream should loop.
430 	 *
431 	 * In this case, it will attempt to restart playback
432 	 * from the beginning instead of stopping at the end.
433 	 *
434 	 * Not all streams may support looping, in particular
435 	 * non-seekable streams. Those streams will ignore the
436 	 * loop setting and just end.
437 	 *
438 	 * Params:
439 	 *     loop = %TRUE if the stream should loop
440 	 */
441 	public void setLoop(bool loop)
442 	{
443 		gtk_media_stream_set_loop(gtkMediaStream, loop);
444 	}
445 
446 	/**
447 	 * Sets whether the audio stream should be muted.
448 	 *
449 	 * Muting a stream will cause no audio to be played, but it
450 	 * does not modify the volume. This means that muting and
451 	 * then unmuting the stream will restore the volume settings.
452 	 *
453 	 * If the stream has no audio, calling this function will
454 	 * still work but it will not have an audible effect.
455 	 *
456 	 * Params:
457 	 *     muted = %TRUE if the stream should be muted
458 	 */
459 	public void setMuted(bool muted)
460 	{
461 		gtk_media_stream_set_muted(gtkMediaStream, muted);
462 	}
463 
464 	/**
465 	 * Starts or pauses playback of the stream.
466 	 *
467 	 * Params:
468 	 *     playing = whether to start or pause playback
469 	 */
470 	public void setPlaying(bool playing)
471 	{
472 		gtk_media_stream_set_playing(gtkMediaStream, playing);
473 	}
474 
475 	/**
476 	 * Sets the volume of the audio stream.
477 	 *
478 	 * This function call will work even if the stream is muted.
479 	 *
480 	 * The given @volume should range from 0.0 for silence to 1.0
481 	 * for as loud as possible. Values outside of this range will
482 	 * be clamped to the nearest value.
483 	 *
484 	 * If the stream has no audio or is muted, calling this function
485 	 * will still work but it will not have an immediate audible effect.
486 	 * When the stream is unmuted, the new volume setting will take effect.
487 	 *
488 	 * Params:
489 	 *     volume = New volume of the stream from 0.0 to 1.0
490 	 */
491 	public void setVolume(double volume)
492 	{
493 		gtk_media_stream_set_volume(gtkMediaStream, volume);
494 	}
495 
496 	/**
497 	 * Pauses the media stream and marks it as ended.
498 	 *
499 	 * This is a hint only, calls to [method@Gtk.MediaStream.play]
500 	 * may still happen.
501 	 *
502 	 * The media stream must be prepared when this function is called.
503 	 *
504 	 * Since: 4.4
505 	 */
506 	public void streamEnded()
507 	{
508 		gtk_media_stream_stream_ended(gtkMediaStream);
509 	}
510 
511 	/**
512 	 * Called by `GtkMediaStream` implementations to advertise the stream
513 	 * being ready to play and providing details about the stream.
514 	 *
515 	 * Note that the arguments are hints. If the stream implementation
516 	 * cannot determine the correct values, it is better to err on the
517 	 * side of caution and return %TRUE. User interfaces will use those
518 	 * values to determine what controls to show.
519 	 *
520 	 * This function may not be called again until the stream has been
521 	 * reset via [method@Gtk.MediaStream.stream_unprepared].
522 	 *
523 	 * Params:
524 	 *     hasAudio = %TRUE if the stream should advertise audio support
525 	 *     hasVideo = %TRUE if the stream should advertise video support
526 	 *     seekable = %TRUE if the stream should advertise seekability
527 	 *     duration = The duration of the stream or 0 if unknown
528 	 *
529 	 * Since: 4.4
530 	 */
531 	public void streamPrepared(bool hasAudio, bool hasVideo, bool seekable, long duration)
532 	{
533 		gtk_media_stream_stream_prepared(gtkMediaStream, hasAudio, hasVideo, seekable, duration);
534 	}
535 
536 	/**
537 	 * Resets a given media stream implementation.
538 	 *
539 	 * [method@Gtk.MediaStream.stream_prepared] can then be called again.
540 	 *
541 	 * This function will also reset any error state the stream was in.
542 	 *
543 	 * Since: 4.4
544 	 */
545 	public void streamUnprepared()
546 	{
547 		gtk_media_stream_stream_unprepared(gtkMediaStream);
548 	}
549 
550 	/**
551 	 * Same as gtk_media_stream_stream_unprepared().
552 	 *
553 	 * Deprecated: Use [method@Gtk.MediaStream.stream_unprepared] instead.
554 	 */
555 	public void unprepared()
556 	{
557 		gtk_media_stream_unprepared(gtkMediaStream);
558 	}
559 
560 	/**
561 	 * Undoes a previous call to gtk_media_stream_realize().
562 	 *
563 	 * This causes the stream to release all resources it had
564 	 * allocated from @surface.
565 	 *
566 	 * Params:
567 	 *     surface = the `GdkSurface` the stream was realized with
568 	 */
569 	public void unrealize(Surface surface)
570 	{
571 		gtk_media_stream_unrealize(gtkMediaStream, (surface is null) ? null : surface.getSurfaceStruct());
572 	}
573 
574 	/**
575 	 * Media stream implementations should regularly call this
576 	 * function to update the timestamp reported by the stream.
577 	 *
578 	 * It is up to implementations to call this at the frequency
579 	 * they deem appropriate.
580 	 *
581 	 * The media stream must be prepared when this function is called.
582 	 *
583 	 * Params:
584 	 *     timestamp = the new timestamp
585 	 */
586 	public void update(long timestamp)
587 	{
588 		gtk_media_stream_update(gtkMediaStream, timestamp);
589 	}
590 }